package cn.admin.config.common.protocol;

import java.io.Serializable;
import java.util.List;

public abstract class DataClientRegReqPacket extends ProtocolPacket {

    public void setAttribute(String name, Serializable value) {

        if (name != null) {
            List<ProtocolElement> elements = this.getAll();
            for (ProtocolElement element : elements) {
                if (element instanceof AttributeElement) {
                    AttributeElement attribute = (AttributeElement) element;
                    if (attribute.name.equals(name)) {
                        if (value == null) {
                            this.removeElement(element);
                        } else {
                            attribute.value = value;
                        }
                        return;
                    }
                }
            }

            if (value != null) {
                AttributeElement element = new AttributeElement(name,value);
                this.addElement(element);
            }
        }

    }

}
